package com.delos.rbac.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.delos.rbac.entity.ResourcesDO;
import com.delos.rbac.mapper.ResourcesMapper;
import com.delos.rbac.mapper.RoleResourceMapper;
import com.delos.rbac.service.IResourceService;
import com.delos.rbac.service.IRoleResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.Collections;
import java.util.Set;

/**
 * 资源服务
 *
 * @author zouyaowen
 * @date 2020-06-28
 */
@Service
public class ResourceServiceImpl extends ServiceImpl<ResourcesMapper, ResourcesDO> implements IResourceService {

    @Autowired
    private IRoleResource roleResource;

    @Override
    public Set<String> getRoleSetByUri(String requestUri) {
        QueryWrapper<ResourcesDO> query = new QueryWrapper<>();
        query.eq("resource_path", requestUri);
        ResourcesDO resourcesDO = this.baseMapper.selectOne(query);
        if (resourcesDO == null) {
            return Collections.emptySet();
        }
        roleResource.getByResourceId(resourcesDO.getId());
        return null;
    }
}
